package com.atguigu.config;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @Description :
 * @Version : V1.0.0
 * @Date : 2022/9/2 11:07
 */
public class LinuxCondition implements Condition {
    /**
     * 匹配接口
     *
     * @param context  判断条件的上下文
     * @param metadata 当前标注了@Conditional注解的注释信息
     * @return
     */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        final Environment environment = context.getEnvironment();
        final String property = environment.getProperty("os.name");

        final BeanDefinitionRegistry registry = context.getRegistry();
        final boolean personContain = registry.containsBeanDefinition("person");
        if (property.contains("linux")) {
            return true;
        }
        return false;
    }
}
